import axios from "axios";
import config from "@/config/config.js";

const toolsLedgerRequest= {
    loadToolLedger(ledger,page=1,limit=10,callBack){
        let url = config.toolBaseUrl+"/ledger/list?page="+page+"&limit="+limit;
        if (ledger){
            if (ledger.toolLedgerCode){
                url += "&toolLedgerCode="+ledger.toolLedgerCode;
            }
            if (ledger.toolLedgerName){
                url += "&toolLedgerName="+ledger.toolLedgerName;
            }
            if (ledger.maintainType){
                url += "&maintainType="+ledger.maintainType;
            }
            if (ledger.toolLedgerBrand){
                url += "&toolLedgerBrand="+ledger.toolLedgerBrand;
            }
            if (ledger.toolLedgerSpec){
                url += "&toolLedgerSpec="+ledger.toolLedgerSpec;
            }
            if (ledger.toolLedgerStatus){
                url += "&toolLedgerStatus="+ledger.toolLedgerStatus;
            }
            axios.get(url).then(res=>{
                callBack(res.data);
            })
        }
    },

    addToolLedger(ledger,callBack){
        let url = config.toolBaseUrl+"/ledger/add";
        axios.put(url,ledger).then(res=>{
            callBack(res.data);
        })
    },

    updateToolLedger(ledger,callBack){
        let url = config.toolBaseUrl+"/ledger/update";
        axios.put(url,ledger).then(res=>{
            callBack(res.data)
        })
    },

    selectById(toolLedgerId,callBack){
        let url = config.toolBaseUrl+"/ledger/selectById?toolLedgerId="+toolLedgerId;
        axios.get(url).then(res=>{
            callBack(res.data);
        })
    },

    delete(toolLedgerId,callBack){
        let url = config.toolBaseUrl+"/ledger/delete?toolLedgerId="+toolLedgerId;
        axios.put(url).then(res=>{
            callBack(res.data);
        })
    },

    selectByType(callBack){
        let url = config.toolBaseUrl+"/ledger/selectByType?status="+1;
        axios.get(url).then(res=>{
            callBack(res.data);
        })
    },

}

export default toolsLedgerRequest;